//
//  ThreeViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/3/4.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

let screenMainSize = UIScreen.main.bounds.size;

class ThreeViewController: UIViewController {

    var threeHeaderView:ThreeView?;
    lazy var contentLb:UILabel = {
        let contentLb = UILabel(frame: CGRect.zero);
        contentLb.textColor = .green;
        contentLb.textAlignment = .center;
        contentLb.font = UIFont.systemFont(ofSize: 16);
        contentLb.numberOfLines = 0;
        return contentLb;
    }();
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "图片轮播";
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.
        self.onCreateUIForNavigation();
        self.onCreateUIForView();
    }
    

    //TODO:创建UI
    func onCreateUIForNavigation() {
        let backItem = UIBarButtonItem(title: "返回", style: .plain, target: self, action: #selector(backAction));
        self.navigationItem.leftBarButtonItem = backItem;
        
        self.navigationController?.navigationBar.barTintColor = .yellow;
        
        //设备背景图片barTintColor就无效
//        self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default);
    }
    
    func onCreateUIForView() {
        let headerView = ThreeView(frame: CGRect(x: 0, y: 88, width: screenMainSize.width, height: 340));
        self.view.addSubview(headerView);
        self.threeHeaderView = headerView;
        let picArr:NSArray = ["picture_01","onepiece","颜色值16进制表"];
        headerView.onAddPitureForVC(picArr: picArr);
        headerView.onClickImageForBlock { (tag) in
            self.onChangeTitleForHeaderView(tag: tag);
        }
        
        self.view.addSubview(self.contentLb);
        self.contentLb.frame = CGRect(x: 0, y: headerView.frame.maxY+20, width: headerView.frame.width, height: 60);
    }

    //TODO:Actions
    //TODO:Private Actions
    @objc func backAction() {
        self.threeHeaderView?.destroyTimer();
        self.navigationController?.dismiss(animated: true, completion: nil);
    }
    
    func onChangeTitleForHeaderView(tag:Int) {
        switch tag-400 {
        case 1:
            self.contentLb.text = "外交部：截至3月2日 62个国家和7个国际组织向中国捐赠防疫物资";
        case 2:
            self.contentLb.text = "湖北新增新冠肺炎确诊病例134例 其中武汉131例";
        case 3:
            self.contentLb.text = "伊朗累计确诊2922例新冠肺炎病例 鲁哈尼要求美国取消药物制裁";
        default:
            ""
        }
    }
    
    //TODO:Public Actions
}
